package com.cloudwebrtc.voip.sipenginev2.impl;

import com.cloudwebrtc.voip.sipenginev2.SipProfile;
import com.cloudwebrtc.voip.sipenginev2.SipTransportType;

public class SipProfileImpl extends SipProfile {
	//implement for SipProfile_JNI.cpp
	private long nativePtr = 0;
	
	private native void SetStringValue(long nativePtr, String key, String value);
	private native void SetIntgerValue(long nativePtr, String key, int value);
	private native void SetBooleanValue(long nativePtr, String key, boolean value);
	
	private native String GetStringValue(long nativePtr, String key);
	private native int GetIntgerValue(long nativePtr, String key);
	private native boolean GetBooleanValue(long nativePtr, String key);

	public long GetNativePtr()
	{
		return nativePtr;
	}
	
	public SipProfileImpl(long aNativePtr)
	{
		nativePtr = aNativePtr;
		Load();
	}
	
	public void Load()
	{
		profile_name = GetStringValue(nativePtr,"profile_name");
		username = GetStringValue(nativePtr,"username");
		displayname = GetStringValue(nativePtr,"displayname");
		auth_name = GetStringValue(nativePtr,"auth_name");
		password = GetStringValue(nativePtr,"password");
		domain = GetStringValue(nativePtr,"domain");
		server = GetStringValue(nativePtr,"server");
		proxy = GetStringValue(nativePtr,"proxy");
		realm = GetStringValue(nativePtr,"realm");
		
		keepalive = GetBooleanValue(nativePtr,  "keepalive");
		register_expire = GetIntgerValue(nativePtr,  "register_expire");
		
		
		
		int trans_type_int = GetIntgerValue(nativePtr, "trans_type");
		if(trans_type_int == SipTransportType.UDP.IntgerValue())
			trans_type = SipTransportType.UDP;
		else if(trans_type_int == SipTransportType.TCP.IntgerValue())
			trans_type =  SipTransportType.TCP;
		else if(trans_type_int == SipTransportType.TLS.IntgerValue())
			trans_type =  SipTransportType.TLS;
		
		webrtc_mode = GetBooleanValue(nativePtr,  "webrtc_mode");
		send_register = GetBooleanValue(nativePtr,  "send_register");
		contact_add_apns_token = GetBooleanValue(nativePtr,  "contact_add_apns_token");
		apns_token = GetStringValue(nativePtr,"apns_token");
	}

	@Override
	public void Save() {
	
		SetStringValue(nativePtr,"profile_name",profile_name);
		SetStringValue(nativePtr,"username",username);
		SetStringValue(nativePtr,"displayname",displayname);
		SetStringValue(nativePtr,"auth_name",auth_name);
		SetStringValue(nativePtr,"password",password);
		SetStringValue(nativePtr,"domain",domain);
		SetStringValue(nativePtr,"server",server);
		SetStringValue(nativePtr,"proxy",proxy);
		SetStringValue(nativePtr,"realm",realm);
		SetStringValue(nativePtr,"apns_token",apns_token);
		
		SetIntgerValue(nativePtr,"register_expire",register_expire);
		SetIntgerValue(nativePtr,"trans_type",trans_type.IntgerValue());
		
		SetBooleanValue(nativePtr,"keepalive",keepalive);
		SetBooleanValue(nativePtr,"webrtc_mode",webrtc_mode);
		SetBooleanValue(nativePtr,"send_register",send_register);
		SetBooleanValue(nativePtr,"contact_add_apns_token",contact_add_apns_token);
	}
}
